package wens.pig.base.plugin.form;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.exception.KDBizException;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.PreOpenFormEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;

/**
 * @author xn-lijunjie
 * @since 2022年09月14日-19:51
 */
public class OrgCheckWSPlugin extends AbstractFormPlugin {
    @Override
    public void preOpenForm(PreOpenFormEventArgs e) {
        super.preOpenForm(e);
        long orgId = RequestContext.get().getOrgId();
        DynamicObject object = BusinessDataServiceHelper.loadSingle(orgId, "bos_org");
        String name = object.getString("name");
        if (!"温氏集团".equals(name)) {
            e.setCancel(true);
            e.setCancelMessage("“请切换到温氏集团下进行新增、删除、启用、禁用操作”");
        }
    }
    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
        super.beforeDoOperation(args);
        long orgId = RequestContext.get().getOrgId();
        DynamicObject object = BusinessDataServiceHelper.loadSingle(orgId, "bos_org");
        String name = object.getString("name");
        if (!"温氏集团".equals(name)) {
            throw new KDBizException("“请切换到温氏集团下进行新增、删除、启用、禁用操作”");
        }
    }

}
